tvinputdevice api the tv input device api provides functions to subscribe key events of the input device the following remote control keys are mandatory input device keys they are available to an application on any tizen tv arrowleft, arrowup, arrowright, arrowdown enter back the tizen tv may provide additional keys depending on a particular input device an application can handle device dependent key events after registration since 2 3 summary of interfaces and methods interface method tvinputdevicemanagerobject inputdevicekey tvinputdevicemanager inputdevicekey[] getsupportedkeys inputdevicekey? getkey inputdevicekeyname keyname void registerkey inputdevicekeyname keyname void unregisterkey inputdevicekeyname keyname void registerkeybatch inputdevicekeyname[] keynames, optional successcallback? successcallback, optional errorcallback? errorcallback void unregisterkeybatch inputdevicekeyname[] keynames, optional successcallback? successcallback, optional errorcallback? errorcallback 1 type definitions 1 1 inputdevicekeyname name which identifies the key typedef domstring inputdevicekeyname; name of the key may be, for example volumeup volumedown channelup channeldown the actual list of supported keys depends on the platform 2 interfaces 2 1 tvinputdevicemanagerobject the tvinputdevicemanager interface defines what is instantiated in the tizen object [nointerfaceobject] interface tvinputdevicemanagerobject { readonly attribute tvinputdevicemanager tvinputdevice; }; tizen implements tvinputdevicemanagerobject; since 2 3 there is a tizen tvinputdevice object that allows accessing the functionality of the tv input device api 2 2 inputdevicekey the inputdevicekey interface stores information about the key [nointerfaceobject] interface inputdevicekey { readonly attribute inputdevicekeyname name; readonly attribute long code; }; since 2 3 attributes readonly inputdevicekeyname name the name of the key, for example "volumeup" or "channeldown" if the key is listed in the dom level 3 keyboardevent key values specification, the name attribute is equal to the key value specified there the media controller keys section is the most relevant to the input device api if the "dom level 3 keyboardevent key value" does not contain appropriate entry for the key, then the input device provides a device specific name since 2 3 readonly long code the numeric code of the key, like 37 or 13 this is the keycode attribute value of the key event generated by the key since 2 3 2 3 tvinputdevicemanager the tvinputdevicemanager interface provides the features to check for availability and register for input device events [nointerfaceobject] interface tvinputdevicemanager { inputdevicekey[] getsupportedkeys raises webapiexception ; inputdevicekey? getkey inputdevicekeyname keyname raises webapiexception ; void registerkey inputdevicekeyname keyname raises webapiexception ; void unregisterkey inputdevicekeyname keyname raises webapiexception ; void registerkeybatch inputdevicekeyname[] keynames, optional successcallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void unregisterkeybatch inputdevicekeyname[] keynames, optional successcallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; }; since 2 3 methods getsupportedkeys retrieves the list of keys can be registered with the registerkey method inputdevicekey[] getsupportedkeys ; since 2 3 mandatory keys will not be retrieved by this method privilege level public privilege http //tizen org/privilege/tv inputdevice exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method with error type unknownerror in case of any error code example var i, keycode = {}, supportedkeys; supportedkeys = tizen tvinputdevice getsupportedkeys ; for i = 0; i < supportedkeys length; i++ { keycode[supportedkeys[i] name] = supportedkeys[i] code; } if keycode hasownproperty "channelup" { tizen tvinputdevice registerkey "channelup" ; } window addeventlistener "keydown", function keyevent { // identify the key by the numeric code from the keyevent if keyevent keycode === keycode channelup { console log "the channel up was pressed" ; } } ; getkey returns information about the key which has the given name inputdevicekey? getkey inputdevicekeyname keyname ; since 2 3 privilege level public privilege http //tizen org/privilege/tv inputdevice parameters keyname the name of the key to retrieve return value inputdevicekey inputdevicekey object for the given key name, or null if the key is not supported exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method with error type invalidvalueserror if the given keyname is invalid e g name is empty string with error type unknownerror in any other error case registerkey registers an input device key to receive dom keyboard event when it is pressed or released void registerkey inputdevicekeyname keyname ; since 2 3 when an application wants to react to the input device keys being pressed, it should register this key an application cannot register the mandatory keys arrowleft, arrowright, arrowup, arrowdown, enter, back privilege level public privilege http //tizen org/privilege/tv inputdevice parameters keyname the name of the key which should generate dom key events when pressed exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method with error type invalidvalueserror, if the given keyname is invalid or not supported e g name is empty string with error type unknownerror in any other error case code example var keys = ["volumeup", "volumedown"], i; for i = 0; i < keys length; i++ { try { tizen tvinputdevice registerkey keys[i] ; } catch error { console log "failed to register " + keys[i] + " " + error ; } } unregisterkey unregisters an input device key void unregisterkey inputdevicekeyname keyname ; since 2 3 privilege level public privilege http //tizen org/privilege/tv inputdevice parameters keyname the name of the key which should not be monitored any longer exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method with error type invalidvalueserror, if the given keyname is invalid or not supported e g name is empty string with error type unknownerror in any error case code example tizen tvinputdevice unregisterkey "volumedown" ; registerkeybatch registers a batch of input device keys to receive dom keyboard events when any of them is pressed or released void registerkeybatch inputdevicekeyname[] keynames, optional successcallback? successcallback, optional errorcallback? errorcallback ; since 2 4 when an application wants to react to the input device key presses, it should register those keys an application cannot register the mandatory keys arrowleft, arrowright, arrowup, arrowdown, enter, back the errorcallback is launched with this error type invalidvalueserror if any of the given keynames is invalid or not supported unknownerror in case of any other error privilege level public privilege http //tizen org/privilege/tv inputdevice parameters keynames the array with the names of the keys which will generate dom key events when they are pressed successcallback [optional] [nullable] callback method to be invoked when keys are registered errorcallback [optional] [nullable] callback method to be invoked when an error has occurred exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method with error type invalidvalueserror, if any of the given keynames is invalid or not supported e g name is empty string with error type typemismatcherror, if any input parameter is not compatible with the expected type for that parameter with error type unknownerror in any other error case code example function errorcb err { console log 'the following error occurred ' + err name ; } function successcb { console log 'registered successfully' ; } var keys = ["volumeup", "volumedown"]; tizen tvinputdevice registerkeybatch keys, successcb, errorcb ; unregisterkeybatch unregisters a batch of input device keys void unregisterkeybatch inputdevicekeyname[] keynames, optional successcallback? successcallback, optional errorcallback? errorcallback ; since 2 4 the errorcallback is launched with this error type invalidvalueserror if any of the given keynames is invalid or not supported unknownerror in case of any other error privilege level public privilege http //tizen org/privilege/tv inputdevice parameters keynames the array with the names of the keys to unregister successcallback [optional] [nullable] callback method to be invoked when keys are unregistered errorcallback [optional] [nullable] callback method to be invoked when an error has occurred exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method with error type invalidvalueserror, if any of the given keynames is invalid or not supported e g name is empty string with error type typemismatcherror, if any input parameter is not compatible with the expected type for that parameter with error type unknownerror in any error case code example function errorcb err { console log 'the following error occurred ' + err name ; } function successcb { console log 'unregistered successfully' ; } var keys = ["volumeup", "volumedown"]; tizen tvinputdevice unregisterkeybatch keys, successcb, errorcb ; 3 related feature you can check if this api is supported with tizen systeminfo getcapability and decide enable/disable codes that need this api to guarantee the running of this application on a device with a tv input device support, define the following requirements in the config file http //tizen org/feature/tv inputdevice for more information, see application filtering 4 full webidl module tvinputdevice { typedef domstring inputdevicekeyname; [nointerfaceobject] interface tvinputdevicemanagerobject { readonly attribute tvinputdevicemanager tvinputdevice; }; tizen implements tvinputdevicemanagerobject; [nointerfaceobject] interface inputdevicekey { readonly attribute inputdevicekeyname name; readonly attribute long code; }; [nointerfaceobject] interface tvinputdevicemanager { inputdevicekey[] getsupportedkeys raises webapiexception ; inputdevicekey? getkey inputdevicekeyname keyname raises webapiexception ; void registerkey inputdevicekeyname keyname raises webapiexception ; void unregisterkey inputdevicekeyname keyname raises webapiexception ; void registerkeybatch inputdevicekeyname[] keynames, optional successcallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void unregisterkeybatch inputdevicekeyname[] keynames, optional successcallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; }; };